<?php

class Kd_Web_Messager {

    private $_session = NULL;
    private $_informKey = '__informs';
    private $_errorKey = '__errors';

    public function __construct(){
        $this->_session = Kd_Web::getSession();
    }

    public function addInform($content){
        $arr = $this->_session->get($this->_informKey, array());
          if(is_array($content)){
            $arr = array_merge($arr, $content);
        }else{
            $arr[] = $content;
        }
        $this->_session->set($this->_informKey, $arr);
        return $this;
    }
    
    public function getInform(){
        $result = $this->_session->get($this->_informKey);
        $this->_session->remove($this->_informKey);
        return $result;
    }

    public function addError($content){
        $arr = $this->_session->get($this->_errorKey, array());
        if(is_array($content)){
            $arr = array_merge($arr, $content);
        }else{
            $arr[] = $content;
        }
        $this->_session->set($this->_errorKey, $arr);
        return $this;
    }
    
    public function getError(){
        $result = $this->_session->get($this->_errorKey);
        $this->_session->remove($this->_errorKey);
        return $result;
    }
}